package com.example.leetcode.trainingcamp.week4.Sunday;

import java.util.Comparator;
import java.util.PriorityQueue;

public class Test148 {

    public ListNode sortList(ListNode head) {
        if (head == null){
            return head;
        }
        PriorityQueue<ListNode> queue = new PriorityQueue<>(Comparator.comparingInt(x -> x.val));
        ListNode pre = head;
        ListNode newHead = new ListNode();
        ListNode tail = newHead;
        while (pre != null){
            queue.offer(pre);
            pre = pre.next;
        }
        int size = queue.size();
        for (int i =0;i<size;i++){
            System.out.println();
            ListNode poll = queue.poll();
            tail.next = poll;
            tail = poll;
        }
        tail.next = null;
        return newHead.next;
    }
}
